package org.deltaset.samples.library.domain;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.deltaset.meta.annotation.DsLabel;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author dmakariev
 */
public abstract class AbstractAnimalRepository {

    public AbstractAnimalRepository() {
    }
    private EntityManager entityManager;

    protected EntityManager getEntityManager() {
        return entityManager;
    }

    public final Animal newEntity() {
        return new Animal();
    }

    @Transactional
    public final Animal new12Records(@DsLabel("new records") Integer numberOfNewRecords) {
        for (int i = 10; i < numberOfNewRecords + 10; i++) {
            final Animal animal = new Animal();
            animal.setName("record " + i);
            entityManager.merge(animal);
        }
        return new Animal();
    }

    public void doSomething() {
        //do nothing..
    }

    @PersistenceContext
    void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }
}
